package com.xbongbong.pro.enums;

import com.xbongbong.paas.constant.PaasConstant;
import com.xbongbong.saas.enums.XbbRefTypeEnum;
import com.xbongbong.saas.enums.business.ClueEnum;
import com.xbongbong.saas.enums.business.CustomerManagementEnum;
import lombok.Getter;

import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Objects;

@Getter
public enum FieldConvertDefaultEnum {
    // 默认字段,目前就线索转客户
    COMPANY_NAME(ClueEnum.COMPANY_NAME.getAttr(), CustomerManagementEnum.NAME.getAttr()),
    CONTACT(ClueEnum.CONTACT.getAttr(), null),
    SUB_TYPE(ClueEnum.PHONE.getAttr() + ".text_1", CustomerManagementEnum.PHONE.getAttr() + ".text_1"),
    SUB_PHONE(ClueEnum.PHONE.getAttr() + ".text_2", CustomerManagementEnum.PHONE.getAttr() + ".text_2"),
    LABEL(ClueEnum.LABEL.getAttr(), CustomerManagementEnum.LABEL.getAttr()),
    ADDRESS(ClueEnum.ADDRESS.getAttr(), CustomerManagementEnum.ADDRESS.getAttr()),
    OWNER_ID(ClueEnum.OWNER_ID.getAttr(), null),
    COUSERID(ClueEnum.COUSERID.getAttr(), null),
    MEMO(ClueEnum.MEMO.getAttr(), CustomerManagementEnum.MEMO.getAttr()),
    ;
    /**
     * 线索字段attr
     */
    private String clueAttr;

    /**
     * 客户字段attr
     */
    private String cusAttr;

    FieldConvertDefaultEnum(String clueAttr, String cusAttr) {
        this.clueAttr = clueAttr;
        this.cusAttr = cusAttr;
    }

    public static Map<String, String> getRelationAttrMap(Integer businessType) {
        Map<String, String> map = new LinkedHashMap<>(PaasConstant.DEFAULT_INITIAL_CAPACITY);
        XbbRefTypeEnum xbbRefTypeEnum = XbbRefTypeEnum.getByCode(businessType);
        switch (xbbRefTypeEnum) {
            case CUSTOMER_MANAGEMENT:
                for (FieldConvertDefaultEnum defaultEnum : values()) {
                    if (Objects.nonNull(defaultEnum.getCusAttr())) {
                        map.put(defaultEnum.getClueAttr(), defaultEnum.getCusAttr());
                    }
                }
                break;
            default:
                break;
        }
        return map;
    }
}
